<?php
class ScoopitSettings {

	function __construct() {
		add_action('admin_menu', array($this, 'shareOnCreateMenu'));

	}

	function shareOnCreateMenu() {
		add_options_page('ShareOn Options', 'ShareOn', 'manage_options', 'share_on', array($this, 'shareOnOptionsPage'));
		add_action('admin_init', array($this, 'shareOnInit'));
	}
	
	function shareOnInit(){
	
		register_setting('share_on_options', 'share_on', array($this, 'shareOnValidate'));
		add_settings_section('share_on_key_secret', 'Scoop.It API', array($this,'scoopitHeading'), 'share_on_options');
		add_settings_field('share_on_field_key', 'Scoop.It Consumer Key: ', array($this,'scoopitKey'), 'share_on_options', 'share_on_key_secret');
		add_settings_field('share_on_field_secret', 'Scoop.It Consumer Secret: ', array($this,'scoopitSecret'), 'share_on_options', 'share_on_key_secret');	
	}

	function shareOnOptionsPage() {
		if (!current_user_can('manage_options'))  {
			wp_die( 'You do not have sufficient permissions to access this page.' );
		}
		
		?>
		<div class="wrap">
			<div id="icon-options-general" class="icon32"><br></div>
			<h2>Share On Scoop.It  <img src="http://www.scoop.it/resources/img/api/poweredbyscoopit_20_transp.png" alt="Powered By Scoop.It"></h2>
			<form method="post" action="options.php">
				<?php settings_fields('share_on_options'); ?>
				<?php do_settings_sections('share_on_options'); ?>	
				<?php submit_button('Save') ?>
			</form>
		</div>
		<?php
	}
	
	function shareOnValidate($input) {
		$input['scoopit_key'] = wp_filter_nohtml_kses($input['scoopit_key']);
		$input['scoopit_secret'] = wp_filter_nohtml_kses($input['scoopit_secret']);
		return $input;
	}
	
	function scoopitHeading() {
 		?>
 		<p>Enter in your consumer key and secret in the appropriate fields</p> 
 		<?php
	}

	function scoopitKey() {
		$options = get_option('share_on'); 
		?><input type="text" name="share_on[scoopit_key]" value="<?php echo (empty($options['scoopit_key']) ? '' : $options['scoopit_key']); ?>" /><?php
	}

	function scoopitSecret() {
		$options = get_option('share_on'); 
		?><input type="text" name="share_on[scoopit_secret]" value="<?php echo (empty($options['scoopit_secret']) ? '' : $options['scoopit_secret']); ?>" /><?php
	}
}
?>